package com.api.gbhg.liuwenbo.action;

import com.api.gbhg.lbj.dao.GeneralProjectDao;
import com.api.gbhg.liuwenbo.dao.DataBaseUtil;
import com.api.gbhg.zengping.action.BudgetLines;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.api.gbhg.zengping.utils.DateUtil;
import com.kingbase8.util.LOGGER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 办公用品定额包干经费(经费额度管理)
 */

public class OfficeSuppliesBudget implements Action {
    private static final Logger LOGGER = LoggerFactory.getLogger("gbhg");
    @Override
    public String execute(RequestInfo requestInfo) {
        PropertyManagementCostDao pdao = new PropertyManagementCostDao();
        RecordSet rs = DataBaseUtil.getRs(requestInfo.getRequestid(),"uf_bgypbgjfbb");
        Map<String,String> map=new HashMap<>();
        String requestid = requestInfo.getRequestid();
        RecordSet recordSet = GeneralProjectDao.deleteWorkflowByid(requestid);
        recordSet.next();
        boolean isSuccess=false;
        while (rs.next()){
            map.put("requestId",rs.getStringNoTrim("lcjlsqjlid"));
            map.put("lcbj",rs.getStringNoTrim("lcbj"));
            map.put("lcjlid",rs.getStringNoTrim("lcjlsqjlid"));
            map.put("nd",rs.getStringNoTrim("ysnd"));
            String yszje = rs.getStringNoTrim("yszje");
            if(yszje.isEmpty())
                yszje="0.00";
            map.put("ze",yszje);
            map.put("bmzcjjfl",rs.getStringNoTrim("bmyszcjjfl"));
            map.put("zfjjfl",rs.getStringNoTrim("dyzfjjfl"));
            map.put("syed",yszje);
            map.put("dj","0.00");
            map.put("sbdw",rs.getStringNoTrim("sbdw"));
            map.put("xmmc",rs.getStringNoTrim("xmmin"));
            map.put("modedatamodifier",rs.getStringNoTrim("jbr"));
            map.put("modedatamodifydatetime", DateUtil.getNowDate());
            map.put("gkdw", rs.getStringNoTrim("gkdw"));
            map.put("sydw", rs.getStringNoTrim("sydw"));
            isSuccess = pdao.insertBudgeLines(map);
        }
        if(!isSuccess){
            LOGGER.info("============================经费额度同步失败,数据同步异常======================================");
            requestInfo.getRequestManager().setMessagecontent("同步经费额度数据异常");
            requestInfo.getRequestManager().setMessageid("1");
            return FAILURE_AND_CONTINUE;
        }
        LOGGER.info("============================经费额度同步OK======================================");
        return SUCCESS;
    }





}
